package com.qf.blog.controller;


import com.qf.blog.commons.utils.R;
import com.qf.blog.commons.utils.UserThreadLocal;
import com.qf.blog.dto.TokenDto;

import com.qf.blog.service.impl.LikeService;
import com.qf.blog.vo.LikeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/like")
public class LikeController {

    @Autowired
    private LikeService likeService;

    @RequestMapping("/clickLike")
    @ResponseBody
    @CrossOrigin
    public R click(@RequestBody LikeVo likeVo) {

        // 1.判断用户是否登录
        TokenDto userToken = UserThreadLocal.get();

        if (userToken == null) {
            return R.error("请先登录");
        }

        // 2.把登录的用户Id封装到likeVo
        likeVo.setUserId(userToken.getUserId());

        // 3.实现点赞
        likeService.onClick(likeVo);
        return R.success();
    }
}
